import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ty_smart_watch/common/images_url.dart';
import 'package:ty_smart_watch/page/sport/sport_detail_second/chart_view.dart';
import 'package:ty_smart_watch/page/sport/sport_detail_second/data_grid.dart';

import '../../../utils/Log.dart';
import '../controller/sport_controller.dart';

class SportDetailSecondPage extends StatefulWidget {
  const SportDetailSecondPage({super.key});

  @override
  State<SportDetailSecondPage> createState() => _SportDetailSecondPageState();
}

class _SportDetailSecondPageState extends State<SportDetailSecondPage> {
  int _id = 0;
  SportController sportController = Get.find();

  @override
  void initState() {
    super.initState();
    _id = Get.arguments["id"];
    Log.d("second page Id: $_id");
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text("${sportController.sportList.value[_id].title} 月"),
        leading: IconButton(
          icon: const Icon(Icons.arrow_back_ios),
          onPressed: () {
            Get.back();
          },
        ),
      ),
      body: Column(
        children: [
          Container(
            width: double.infinity,
            color: Color(0xFFEBEBEB),
            child: Container(
              margin: EdgeInsets.all(10),
              padding: EdgeInsets.all(10),
              decoration: const BoxDecoration(
                color: Colors.white,
                //圆角半径
                borderRadius: BorderRadius.all(Radius.circular(12.0)),
                // boxShadow: [
                //   BoxShadow(color: Colors.grey, offset: Offset(0, 0), blurRadius: 8, spreadRadius: 0),
                // ],
              ),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Row(
                    children: [
                      Image.asset(ICON_CHILD_DISTANCE, width: 30, height: 30),
                      Text(getSportTitle(_id)),
                    ],
                  ),
                  SizedBox(height: 20),
                  ChartView(color: Color(0xFF157FEB)),
                ],
              ),
            ),
          ),
          DataGrid(),
        ],
      ),
    );
  }

  String getSportTitle(int id) {
    String text;
    if (id == 0x14 /*瑜伽*/) {
      text = "本月${sportController.sportList.value[_id].title} (热量)";
    } else {
      text = "本月${sportController.sportList.value[_id].title} (公里)";
    }
    return text;
  }
}
